package rn.automacao.persistencia;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

import rn.automacao.banco.Conexao;
import rn.automacao.dominio.AtendimentoVO;
import rn.automacao.dominio.TipoVO;

public class RelatorioDAO {

	static Connection conn = null;

	static PreparedStatement ps = null;
	Statement stmt = null;

	static ResultSet rs = null;

	public static Collection<Object> pesquisar(int codFunc, int mes, int ano) {

		Collection<Object> os = new ArrayList<Object>();
		conn = Conexao.getInstance().abreConexao();
		try {
			ps = conn.prepareStatement("SELECT * FROM OS WHERE CODFUNC ="+codFunc+" AND data_execucao BETWEEN '"+mes+"/01/"+ano+"' AND '"+mes+"/30/"+ano+"' ORDER BY CODOS");
			rs = ps.executeQuery();

			while (rs.next()) {
				AtendimentoVO atendos = new AtendimentoVO();
				atendos.setCodOS(rs.getInt(1));
				atendos.setItemOS(rs.getInt(2));
				atendos.setTipoOS((TipoVO)new TipoDAO().pesquisarTipoOS(rs.getInt(4), "codtipo"));
				atendos.setDataAbertura(rs.getDate(5));
				atendos.setDataExecucao(rs.getDate(6));
				atendos.setValor(rs.getDouble(7));
				atendos.setPaga(rs.getByte(9));
				os.add(atendos);
			}
			return os;

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return null;
	}
}
